package com.lv.thumb.exception;

import com.lv.thumb.common.BaseResponse;
import com.lv.thumb.common.ErrorCode;
import com.lv.thumb.common.ResultUtils;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 *
 */
@RestControllerAdvice
@Hidden
@Slf4j
public class GlobalExceptionHandler {

//    @ExceptionHandler(BusinessException.class)
//    public BaseResponse<?> businessExceptionHandler(BusinessException e) {
//        log.error("BusinessException", e);
//        return ResultUtils.error(e.getCode(), e.getMessage());
//    }
    @ExceptionHandler(RuntimeException.class)
    public BaseResponse<?> runtimeExceptionHandler(RuntimeException e) {
        log.error(e.getMessage(), e);
        return ResultUtils.error(ErrorCode.OPERATION_ERROR, e.getMessage());
    }
//    @ExceptionHandler(RuntimeException.class)
//    public BaseResponse<?> runtimeExceptionHandler(RuntimeException e) {
//        log.error("RuntimeException", e);
//        return ResultUtils.error(ErrorCode.SYSTEM_ERROR, "系统错误");
//    }
}
